package cn.ekuma.data.log;

import java.util.Date;

import cn.ekuma.data.dao.AppLogerDAO;
import cn.ekuma.data.dao.bean.AppLoger;

import com.openbravo.data.basic.BasicException;
import com.openbravo.data.loader.I_Session;
import com.openbravo.data.loader.Session;

public class DataLogicLoger {
   public static int BEAN_Insert=0;
   public static int BEAN_Update=1;
   public static int BEAN_Delete=2;
   
   public static int USER_Log=-1;//用于记录用户的登入，退出，修改密码等相关记录


   private static DataLogicLoger INSTANCE;
   private String userId;
   private String hostName;
   private AppLogerDAO appLogerDAO;
   
   public static void init(I_Session s,String userId,String hostName){
	   if(INSTANCE==null){
		  INSTANCE=new DataLogicLoger();
		  INSTANCE.appLogerDAO=new AppLogerDAO(s);
	   }
	   INSTANCE.userId=userId;
	   INSTANCE.hostName=hostName; 
   };
   
   public static void log(AppLoger obj) throws BasicException{
	   if(INSTANCE!=null)
		   INSTANCE.insert(obj);
   }
   
   public static boolean isLogAble(){
	   return INSTANCE!=null;
   }
   
   void insert(AppLoger obj) throws BasicException{
	   obj.setCreateDate(new Date());
	   obj.setUserId(userId);
	   obj.setHostName(hostName);
	   appLogerDAO.insert(obj);
   }
}
